package com.itheima.controller.pms;

import com.itheima.api.pms.PmsProductService;
import com.itheima.vo.domain.AjaxResult;
import com.itheima.vo.dto.pms.PmsProductDto;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;

@RestController
@RequestMapping("product")
public class PmsProductController {

    @DubboReference
    private PmsProductService pmsProductService;

    /**
     * 1.创建商品
     *
     * @param pmsProductDto
     * @return
     */
    @PostMapping("create")
    public AjaxResult create(@RequestBody PmsProductDto pmsProductDto) {
        return pmsProductService.create(pmsProductDto);
    }

    /**
     * 2.查询商品
     *
     * @param brandId           商品品牌编号
     * @param keyword           商品名称模糊关键字商品名称模糊关键字
     * @param pageNum
     * @param pageSize
     * @param productCategoryId 商品分类编号
     * @param productSn         商品货号
     * @param publishStatus     上架状态
     * @param verifyStatus      审核状态
     * @return
     */
    @GetMapping("list")
    public AjaxResult FindBylist(@RequestParam(value = "brandId", required = false) Integer brandId,
                                 @RequestParam(value = "keyword", required = false) String keyword,
                                 @RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum,
                                 @RequestParam(value = "pageSize", required = false, defaultValue = "5") Integer pageSize,
                                 @RequestParam(value = "productCategoryId", required = false) Integer productCategoryId,
                                 @RequestParam(value = "productSn", required = false) String productSn,
                                 @RequestParam(value = "publishStatus", required = false) Integer publishStatus,
                                 @RequestParam(value = "verifyStatus", required = false) Integer verifyStatus
    ) {
        return pmsProductService.FindBylist(brandId, keyword, pageNum, pageSize, productCategoryId, productSn, publishStatus, verifyStatus);
    }

    /**
     * 3.根据商品名称或货号模糊查询
     *
     * @param keyword
     * @return
     */
    @GetMapping("simpleList")
    public AjaxResult simpleList(@RequestParam(value = "keyword", required = false) String keyword) {
        return pmsProductService.simpleList(keyword);
    }

    /**
     * 4.批量修改删除状态
     * @param deleteStatus
     * @param ids
     * @return
     */
    @PostMapping("update/deleteStatus")
    public AjaxResult deleteStatus(@RequestParam(value = "deleteStatus", required = true) Integer deleteStatus,
                                   @RequestParam(value = "ids", required = true) ArrayList<Integer> ids) {
        return pmsProductService.deleteStatus(deleteStatus, ids);
    }

    /**
     * 5.批量设为新品
     * @param newStatus
     * @param ids
     * @return
     */
    @PostMapping("update/newStatus")
    public AjaxResult newStatus(@RequestParam(value = "newStatus", required = true) Integer newStatus,
                                @RequestParam(value = "ids", required = true) ArrayList<Integer> ids) {
        return pmsProductService.newStatus(newStatus, ids);
    }

    /**
     * 6.批量上下架商品
     * @param publishStatus
     * @param ids
     * @return
     */
    @PostMapping("update/publishStatus")
    public AjaxResult publishStatus(@RequestParam(value = "publishStatus", required = true) Integer publishStatus,
                                    @RequestParam(value = "ids", required = true) ArrayList<Integer> ids) {
        return pmsProductService.publishStatus(publishStatus, ids);
    }

    /**
     * 7.批量推荐商品
     * @param recommendStatus
     * @param ids
     * @return
     */
    @PostMapping("update/recommendStatus")
    public AjaxResult recommendStatus(@RequestParam(value = "recommendStatus", required = true) Integer recommendStatus,
                                      @RequestParam(value = "ids", required = true) ArrayList<Integer> ids) {
        return pmsProductService.recommendStatus(recommendStatus, ids);
    }

    /**
     * 8.批量修改审核状态
     * @param detail
     * @param verifyStatus
     * @param ids
     * @return
     */
    @PostMapping("update/verifyStatus")
    public AjaxResult verifyStatus(@RequestParam(value = "detail", required = true) String detail,
                                   @RequestParam(value = "verifyStatus", required = true) Integer verifyStatus,
                                   @RequestParam(value = "ids", required = true) ArrayList<Integer> ids) {
        return pmsProductService.verifyStatus(detail,verifyStatus, ids);
    }

    /**
     * 9.更新商品
     * @param id
     * @param pmsProductDto
     * @return
     */
    @PostMapping("update/{id}")
    public AjaxResult updateWithId(@PathVariable(value = "id", required = true) Integer id,
                                   @RequestBody PmsProductDto pmsProductDto) {
        return pmsProductService.updateWithId(id, pmsProductDto);
    }

    /**
     * 10.根据商品id获取商品编辑信息
     * @param id
     * @return
     */
    @GetMapping("updateInfo/{id}")
    public AjaxResult updateInfoWithId(@PathVariable(value = "id", required = true) Integer id) {
        return pmsProductService.updateInfoWithId(id);
    }
}
